package top.xtcoder.jdcbase.base.config;

import cn.hutool.core.util.StrUtil;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoDatabase;
import com.mongodb.client.gridfs.GridFSBucket;
import com.mongodb.client.gridfs.GridFSBuckets;

@Configuration
public class MongoConfig {
	@Value("${spring.data.mongodb.database:}")
	private String db;
	
	@Bean
	public GridFSBucket getGridFSBucket(MongoClient mongoClient) {
		if(StrUtil.isBlank(db)) {
			return null;
		}
		MongoDatabase mongoDatabase = mongoClient.getDatabase(db);
		GridFSBucket bucket = GridFSBuckets.create(mongoDatabase);
		return bucket;
	}
}
